using System;
using System.Web.Mvc;
using System.Web.Routing;
using EBE.COM.Core.Models;

namespace EBE.COM.Web.Areas.Admin.Controllers
{
  public abstract class ControllerBase : Controller
  {
    private const string SessionName = "LoggedUser";

    protected User LoggedUser
    {
      get
      {
        if (HttpContext.Session != null)
          return (User)HttpContext.Session[SessionName];
        throw new Exception(string.Format("Exception with [{0}] HttpContext.Session", SessionName));
      }
      set
      {
        if (HttpContext.Session != null) HttpContext.Session.Add(SessionName, value);
      }
    }

    //// http://stackoverflow.com/questions/1490401/redirecting-to-specified-controller-and-action-in-asp-net-mvc-action-filter
    //protected override void OnActionExecuting(ActionExecutingContext filterContext)
    //{
    //  if (LoggedUser == null && (string)filterContext.RouteData.Values["controller"] != "Login")
    //  {
    //    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "Controller", "Login" }, { "Action", "Index" } });
    //  }
    //  base.OnActionExecuting(filterContext);
    //}
  }
}